#include<iostream>
using namespace std;
typedef unsigned long long  ull;
int n,m,x,y,ans;
ull a[2001][2001],b[2001][2001];
const int mx[]={1,0,1,0},my[]={0,1,0,-1};

ull yushu(ull a,ull b){
    while(a != b)
    {
        if(a > b) a -= b;
        else b -= a;
    }
    return a;
}

ull compare(int x,int y){
    ull max = 0,temp=-1;
    for (int i = 0; i < 4; i++)
    {
       if(x+mx[i]<1||x+mx[i]>n||y+my[i]<0||y+my[i]>m)continue;
       temp = yushu(a[x+mx[i]][y+my[i]],a[x][y]);
       if(max<temp) max = temp;
    }
    return max;
}

int bfs(int cnt){
    if(compare(x,y)==1) return cnt;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            
        }
        
    }
    

    return ;
}

int main(int argc, char const *argv[])
{
    scanf("%d%d",&n,&m);
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)scanf("%d",&a[i][j]);
    scanf("%d%d",&x,&y);

    ans = bfs(0);

    return 0;
}
